import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router';

const moduleRoutes: RouteRecordRaw[] = [];
const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
Object.values(modules).forEach((module: any) => {
  moduleRoutes.push(...module.default);
});

const baseRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('@/views/common/Home.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/common/Login.vue'),
    meta: { layout: 'EmptyLayout' },
  },
  {
    path: '/403',
    name: 'Forbidden',
    component: () => import('@/views/error/403.vue'),
    meta: { layout: 'EmptyLayout' },
  },
];

const allRoutes: RouteRecordRaw[] = [...baseRoutes, ...moduleRoutes];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: allRoutes,
});

export default router;
